#include <iostream>
#include <vector>

int n, k;

int last_square(int t, int last_line, int magic_num)
{
	int start = 0;
	if (t <= 80) {
		start += int(t/10) * 101;
		start += (t%10)*11;
	} else {
		start += 808; t -= 80;
		int s = 11*last_line + magic_num;
		if (t <= last_line)     start += 11*t;
		else
		if (t == last_line+1)   start += s;
		else
		if (t <= last_line*2+1) start += s + 11*(t-last_line-1);
		else                    start += s + 11*last_line + 2;
	}
	return start;
}

int calc(int t)
{
	if (t <= 5) return (t-1)*2 + 1;
	else
	if (t <= 15) {
		int start = 9; t -= 5;
		if (t <= 9) start += 11*t;
		else        start += 101;
		return start;
	}
	else {
		int start = 110; t -= 15;

		start += int(t/97778) * 1000001; t %= 97778;
		int tot = 97778 - 92;
		if (t > tot) {
			start += 100001*9 + 10001*9 + 1001*9;
			start += last_square(t - tot, 5, 54);
		} else {
			start += int(t/9778) * 100001; t %= 9778;
			tot = 9778 - 94;
			if (t > tot) {
				start += 10001 * 9 + 1001 * 9;
				start += last_square(t - tot, 6, 41);
			} else {
				start += int(t/978) * 10001; t %= 978;
				tot = 978 - 96;
				if (t > tot) {
					start += 1001*9;
					start += last_square(t - tot, 7, 28);
				} else {
					start += int(t/98) * 1001; t %= 98;
					start += last_square(t, 8, 15);
				}
			}
		}
		return start;
	}
}

int num_self(int x)
{
	int l = 1, r = int(x/10) + 100;
	while (l+1 < r) {
		int mid = (l+r)/2;
		if (calc(mid) < n) l = mid+1;
		else               r = mid;
	}
	int nl = calc(l), nr = calc(r);
	if (nl == n) return l;
	if (nr == n) return r;
	if (nl > n)  return l-1;
	return r-1;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> k;
	std::cout << num_self(n) << "\n";
	int tmp; std::cin >> tmp;
	std::cout << calc(tmp);
	for (int i = 1; i < k; i++) {
		std::cin >> tmp;
		std::cout << " " << calc(tmp);
	}
}

